const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showRoom: false,
        stores: [],
        store_id: 0,
        list_data: [],
        store_label:[],
        lableid:0,
        store_name:''
    },
     //筛选项点击操作
  filter: function (e) {
    var id = e.currentTarget.dataset.id;
    this.setData({
        lableid: id
    })
    this.getStores();
  },
  /** 
   * 开始搜索数据
   */
  startSearch: function(e) {
    var name = e.detail.value['search - input'] ? e.detail.value['search - input'] : e.detail.value;
    if (name) {
      //这里是搜索的逻辑
      this.setData({
        store_name:name
    })
      this.getStores();
    } else {
    //   wx.showModal({
    //     title: '提示',
    //     content: '请输入搜索店铺名',
    //     showCancel: false,
    //     confirmText: "知道了",
    //   });
    this.setData({
        store_name:""
    })
    this.getStores();
    }
},
  getStores: function() {
    wx.showLoading({
        title: '加载中',
      })
    app.ajax({
        url: '/api/index/stores',
        data: {
            label_id:this.data.lableid,
            store_name:this.data.store_name,
        },
        success: res => {
            if (res.code == 1) {
                console.log(123213);
                this.setData({
                    list_data:res.data
                })
            } else {
                this.setData({
                    list_data:[]
                })
                // wx.showToast({
                //     title: '空空如也',
                //     icon: 'none'
                // })
            }
            wx.hideLoading()
        }
    })
},
    callPhone(e) {
        var tel = e.currentTarget.dataset.tel;
        wx.makePhoneCall({
            phoneNumber: tel,
            success: function() {},
        })
    },
    show_room: function(e) {
        var id = e.currentTarget.dataset.id;
        if(id == this.data.store_id){
            this.setData({
                store_id: 0
            })
        }else{
            this.setData({
                store_id: id
            })
        }
    },
    book: function(e) {
        var id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/book/book?id=' + id
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var stores = wx.getStorageSync('stores');
        var store_label = wx.getStorageSync('store_label');
        if(stores){
            this.setData({
                list_data: stores,
                store_label:store_label
            })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    xiangqing: function (e) {
        var id = e.target.dataset.id;
        console.log(id);
        wx.navigateTo({
            url: '/pages/xiangqing/xiangqing?id=' +id,
        })
    },
    
})